home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows News 2010 Summer - Disc 1
/
WN_Ete2010_CD1.iso
/
Onglet5
/
Weezo
/
Weezo setup.exe
/
{code_appDir}
/
www
/
includes
/
uploadFlashWindow.php
< prev
next >
Wrap
PHP Script
|
2010-05-19
|
19KB
|
495 lines
<?php
/**
* Flash file upload script, executed in a popup window
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category NA
* @package NA
* @author Nicolas Bruley / Peer 2 World <contact@weezo.net>
* @copyright 2005-2008 Nicolas Bruley / Peer 2 World
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
* @link http://www.weezo.net
* @since File available since Release 1.2.0
*/
/**
* @desc Insert control needed for toggleing close transfer on upload completed
*
*/
function insertCloseOnCompletedControlFlash(){
$output='<form id="cocForm" name="cocForm" action="'.$_SERVER['PHP_SELF'].'">';
$output.='<input id="transferCloseOnCompleted" type="checkbox" '.((cfRGetVar('transferCloseOnCompleted'))?'checked="checked"':'').' onclick="dgn(\'toggleTransferCloseOnCompleted\').value=this.checked;asyncSubmitForm(\'cocForm\',true)"><input name="toggleTransferCloseOnCompleted" type="text" style="display:none"/> ';
$output.=cfCaption('transferCloseOnFinish');
$output.='</form>';
return $output;
}
define('FLASH_PLAYER_WIDTH',250);
define('FLASH_PLAYER_HEIGHT',23);
require_once(INCLUDE_DIR.'outputFunctions.php');
require_once(INCLUDE_DIR.'transferFunctions.php');
require_once(INCLUDE_DIR.'explorerFunctions.php');
/*
***************************************************************************************************************************
* UPLOAD received
***************************************************************************************************************************
*/
if(isset($_FILES['Filedata'])) {
$_FILES['ulInput']=$_FILES['Filedata'];
require(INCLUDE_DIR.'uploadWindow.php');
}
/*
***************************************************************************************************************************
* Asynchronous requests
***************************************************************************************************************************
*/
if(isset($_POST['asyncRequest'])){
cfAsyncHeader();
//Close-on-upload completed toggle
if(isset($_POST['toggleTransferCloseOnCompleted'])) {
cfRSetVar('transferCloseOnCompleted',(($_POST['toggleTransferCloseOnCompleted']=='true')?true:false));
}
// Create a transfer for upload
if(isset($_POST['createUploadTransfer'])){
if(isset($_POST['overwriteConfirmChecked'])) cfRSetVar('overwriteConfirmChecked',$_POST['overwriteConfirmChecked']);
//cfDbg($_POST,1);
$completeFilename=cfJoinPathFile(cfUTF8Decode($_POST['preUlDir']),cfUTF8Decode(basename($_POST['preUlFile'])));
$completeFilename=str_replace('*resourceBasePath*',cfRGetVar('path'),$completeFilename);
// Forbid if destination file exists and cannot be overwritten
if(file_exists($completeFilename) && (!cfFileRights($completeFilename,'modify') || !is_writable($completeFilename))){
echo cfAsyncXMLJSaction('startSingleUploadProceed("","forbidden")');
}
// Ask for confirmation if destination file exists
elseif($_POST['overwrite']=='ask' && file_exists($completeFilename)){
echo cfAsyncXMLJSaction('startSingleUploadProceed("","confirm")');
}
// Skip if destination file exists
elseif($_POST['overwrite']=='skip' && file_exists($completeFilename)){
echo cfAsyncXMLJSaction('startSingleUploadProceed("","skip")');
}
// Create upload transfer
elseif(cfRGetVar('trackTransfers')){
if(!$tr=tAddUpload(cfUTF8Decode($_POST['preUlDir']), cfUTF8Decode(basename($_POST['preUlFile']))))
echo cfAsyncXMLJSaction('uploadError()');
else
echo cfAsyncXMLJSaction('startSingleUploadProceed("'.$tr->id.'")');
}
else echo cfAsyncXMLJSaction('startSingleUploadProceed("foo")'); // Fake transfer id
}
die(cfAsyncFooter());
}
/*
***************************************************************************************************************************
* Page display
***************************************************************************************************************************
*/
cfInsertHEAD();
if(is_array(cfRGetVar('extensionFilter'))) {
$browseFilter='';
foreach (cfRGetVar('extensionFilter') as $v) $browseFilter.=';*.'.$v;
$browseFilter='{"'.cfCaption('genFiles').'":"'.substr($browseFilter,1).'"}';
}
elseif(is_array(cfRGetVar('fileTypeFilter'))) {
require_once(INCLUDE_DIR.'mime_type.php');
$browseFilter='{';
foreach (cfRGetVar('fileTypeFilter') as $type) {
if($browseFilter!='{') $browseFilter.=', ';
switch ($type){
case 'image':
$browseFilter.='"'.cfCaption('genImages').'":';break;
case 'audio':
$browseFilter.='"'.cfCaption('explorerAudioBrowse').'":';break;
case 'video':
$browseFilter.='"'.cfCaption('genVideos').'":';break;
default:
$browseFilter.='"'.ucfirst($type).'":';
}
$l=strlen($type)+1;
$tmp='';
foreach ($_ENV['weezoMime'] as $ext=>$mime) if(substr($mime,0,$l)==$type.'/'){
$tmp.=';*.'.$ext;
}
$browseFilter.='"'.substr($tmp,1).'"';
}
$browseFilter.='}';
}
else $browseFilter='0';
?>
<script type="text/javascript">
var nbFiles=0;
var uploadsArray={}// Array of files to be uploaded
var uploadId;// Id of currently uploaded file
var initOK=0;
var uploadsCompleted=0; // 1 if all uploads completed
var uploadsInProgress=0; // 1 if uploading
var browseFilter=<?php echo $browseFilter;?>; // Dialog browse file filters
var showAddFilesBt=0; // 1 if html browse button is used instead of flash button
var bytesTotalAll=0; // Total size
var bytesAll=0; // Total uploaded size
var overwrite='ask'; // ask, skip, overwrite
var overwriteConfirmChecked=<?php echo ((cfRGetVar('overwriteConfirmChecked'))?'1':'0');?>; // Server-side default prompt storage
var WAInterval;
var httpsErrorCaption="<?php echo cfCaptionJS('sslFlashImport');?>";
// Debug flash player
function dbg(txt){
//alert(txt)
}
// Init page
function init(){
if(initOK++) return;
initLayout();
updateTotals();
document.onresize=initLayout;
winMe.setTitle("<?php echo cfCaption('genFileUpload')?>")
}
// Called by flash app
function initFlashUpload(){
dgi("loadingIcon").style.display="none";
wl.getFlashPlayer('flashUpload').height=<?php echo FLASH_PLAYER_HEIGHT;?>;
wl.getFlashPlayer('flashUpload').width=<?php echo FLASH_PLAYER_WIDTH;?>;
WAInterval=window.setInterval('initFlashPlayer()',10);
}
// Delayed player config (WA)
function initFlashPlayer(){
var fpw=wl.getFlashPlayer('flashUpload').setBrowseButtonLabel("<?php echo cfCaption('addFiles');?>");
if(fpw) wl.getFlashPlayer('flashUpload').width=fpw+3;
if(browseFilter) wl.getFlashPlayer('flashUpload').setFilter(browseFilter);
window.clearInterval(WAInterval);
if(fpw && phpBrowser=='opera') WAInterval=window.setInterval('resizeFlashPlayer('+fpw+')',10); // Opera WA
// Try to open browse window
try{wl.getFlashPlayer('flashUpload').addFiles();} catch(err){}
}
// Opera WA
function resizeFlashPlayer(fpw){wl.getFlashPlayer('flashUpload').width=fpw+3;window.clearInterval(WAInterval);}
// Resize layout
function initLayout(){
setActualHeight(dgi('frame1'),winMe.getInnerHeight()-ra(getElementStyle(dgi('frame1'),'margin-top',false))-ra(getElementStyle(dgi('frame1'),'margin-bottom',false))-7)
setActualHeight(dgi('uploadsDiv'),actualOffsetBottom(dgi('frame1'))-actualOffsetTop(dgi('uploadsDiv'))-ra(getElementStyle(dgi('frame1'),'padding-bottom',false))-dgi('destination').offsetHeight-ra(getElementStyle(dgi('destination'),'margin-bottom',false))-ra(getElementStyle(dgi('destination'),'margin-top',false))-7);
}
function ra(v){if(v=='auto') return 3; else return v;}
function keyPressed(e) {
if(!e) e=window.event;
if (e.keyCode) keycode=e.keyCode; else keycode=e.which;
if(keycode==27 && !uploadsInProgress) winMe.closeMe();
}
function progressSetError(id){
var iht=dgi('PB'+id).parentNode.innerHTML;
iht='<span'+iht.substr(4,iht.length-8)+'span>';
dgi('PB'+id).parentNode.innerHTML=iht;
}
function sizeFormat(size){
if (size<1024) return size+" B";
if (size<1024*1024) return Math.floor(size/1024)+" KB";
if (size<1024*1024*1024) return Math.floor(size/1024/1024)+" MB";
else return Math.floor(size/1024/1024/1024)+" GB";
}
function updateTotals(){
bytesAll=0;
for(var e in uploadsArray) bytesAll+=uploadsArray[e]['bytes'];
dgi('totals').innerHTML=sizeFormat(bytesAll)+' / '+sizeFormat(bytesTotalAll);
}
function addFiles(){
wl.getFlashPlayer('flashUpload').addFiles(browseFilter);
}
// Browse button clicked
function browseClick(){
// Re-uploading files: clear list
if(uploadsCompleted){
nbFiles=0;
uploadsArray={}
dgi('uploadsDiv').innerHTML='<table style="width:100%;layout:fixed" id="uploadsTable"></table>';
uploadsCompleted=0;
bytesTotalAll=0;updateTotals();
}
}
// Add a file to upload list, called by flash player
function addSingleFile(id,name,size){
// Over max upload file size ?
if(size><?php echo cfGGetVar('uploadMaxFilesize')*1024*1024;?>){
alert("<?php echo cfCaption('configUploadMax').cfCaption('genSeparator').cfGGetVar('uploadMaxFilesize').cfCaption('genSizeMb');?>");
return;
}
// Already exist ?
for(var uaid in uploadsArray){
if(uploadsArray[uaid]['name']==name && uploadsArray[uaid]['size']==size) return;
}
// Insert HTML stuff
var iht=dgi('uploadTemplate').innerHTML.replace(/NAME[?]/,name+'<br><span class="smallFont">('+sizeFormat(size)+')').replace(/ID[?]/g,id).replace(/</g,'<').replace(/>/g,'>').replace(/LABEL/,"<?php echo cfCaption('transfersWaitConfirm');?>");
var className='eTC ';
var nb=0;for(i in uploadsArray) nb++;
if(nb%2) className+='odd'; else className+='even';
if(phpBrowser=='ie'){
iht=dgi('uploadsTable').innerHTML+'<tr class="'+className+'" id="UL'+id+'" eH="1">'+iht+'</tr>';
if(iht.substr(0,15)=='<TBODY></TBODY>') iht=iht.substr(15);
dgi('uploadsDiv').innerHTML='<table style="width:100%;layout:fixed" id="uploadsTable">'+iht+'</table>';
}
else{
subNode=document.createElement('tr');
subNode.setAttribute('class',className);subNode.setAttribute('className',className);
subNode.setAttribute('id','UL'+id);
subNode.setAttribute('eH','1');
dgi('uploadsTable').appendChild(subNode);
subNode.innerHTML=iht;
}
// Add to uploads array
uploadsArray[id]={'state':'pending','name':name,'size':size,'bytes':0}
bytesTotalAll+=size;
updateTotals();
if(!nbFiles) wl.button.enable('startUploads')
nbFiles++;
}
// Remove a file from upload list
function removeSingleFile(id){
if(!dgi('UL'+id) || !uploadsArray[id]) return;
// If upload started, cancel through flash, and wait for cancel event
if(uploadsArray[id]['state']=='started') {
wl.getFlashPlayer('flashUpload').cancelUpload(id);
return;
}
dgi('UL'+id).parentNode.removeChild(dgi('UL'+id));
bytesTotalAll-=uploadsArray[id]['size'];
updateTotals();
delete(uploadsArray[id]);
// Reset odd/even lines
var nb=0;for(i in uploadsArray) {
dgi('UL'+i).className="eTC "+((nb%2)?'odd':'even');
nb++;
}
nbFiles--;
if(!nbFiles) wl.button.disable('startUploads')
while(dgi('uploadsTable').firstChild.nodeType==3) dgi('uploadsTable').removeChild(dgi('uploadsTable').firstChild);
}
// Start uploading list
function startUploads(){
//wl.button.disable('addFiles');
wl.button.disable('startUploads');
winMe.closeable(false);
winMe.reloadable (false);
wl.getFlashPlayer('flashUpload').width=1;
wl.getFlashPlayer('flashUpload').height=1;
wl.button.disable('addFilesBt');
uploadsInProgress=1;
// Start 1st upload
for(id in uploadsArray){
startSingleUpload(id);
break;
}
}
// Start uploading a file
function startSingleUpload(id,forceOverwrite){
uploadId=id;
progressSetPerc('PB'+uploadId,0);
progressSetText('PB'+uploadId,"<?php echo cfCaption('transfersConnecting')?>");
// scroll view to new upload
var eT=dgi('TR'+id).offsetTop;
var sT=dgi('uploadsDiv').scrollTop;
if(eT<sT || eT+dgi('TR'+id).offsetHeight>sT+dgi('uploadsDiv').offsetHeight) dgi('uploadsDiv').scrollTop=eT;
// overwrite existing files
if(forceOverwrite) dgn('overwrite').value='overwrite'; else dgn('overwrite').value=overwrite;
dgn('overwriteConfirmChecked').value=overwriteConfirmChecked;
dgn("preUlFile").value=uploadsArray[id]['name'];
asyncSubmitForm('newUploadTransfer');
}
function startSingleUploadProceed(transferId,action){
id=uploadId;
// Dest file protected
if(action=='forbidden'){
progressSetError(uploadId);
uploadsArray[id]['state']='error';
progressSetText('PB'+uploadId,"<?php echo cfCaption('explorerErrorFileSend2');?>");
uploadProcessNext();
}
// Dest file existing, skip
if(action=='skip'){
uploadsArray[id]['state']='skip';
progressSetText('PB'+uploadId,"<?php echo cfCaption('transfersCanceled');?>");
uploadProcessNext();
}
// Confirm overwrite
else if(action=='confirm'){
var m=new dialogBox({'text':"<?php echo cfCaption('genFileAlreadyExistReplace');?>",'title':uploadsArray[id]['name'],'icon':"<?php echo outIcon('alert');?>",'mask':1,'fade':1,'buttons':{'ok':"<?php echo cfCaption('genYes');?>",'cancel':"<?php echo cfCaption('genNo');?>"},'check':overwriteConfirmChecked,'checkText':"<?php echo cfCaption('dontAskAnymore')?>"},'uploadOverwrite');
m.show();
}
// cancel overwrite
else if(action=='confirm' && !overwriteAsk && !overwriteDefault){
uploadsArray[id]['state']='canceled';
progressSetText('PB'+uploadId,"<?php echo cfCaption('transfersCanceled');?>");
uploadProcessNext();
}
// proceed upload
else{
uploadsArray[id]['state']='started';
//alert("start upload of "+uploadsArray[id]['name'])
var res=wl.getFlashPlayer('flashUpload').startSingleUpload(id,transferId,"<?php echo $_SERVER['PHP_SELF'];?>","<?php echo wSession_id();?>","<?php echo cfUTF8Encode(cfResourceRelativePath(cfRGetVar('efCurrentDirectory')));?>");
if(res==undefined) window.setTimeout('startSingleUploadProceed("'+id+'")',20);
}
}
// Overwrite dialogBox result
function uploadOverwrite(result){
overwriteConfirmChecked=(result['check'])?1:0;
if(result['button']=='ok') {
if(overwriteConfirmChecked) overwrite='overwrite';
startSingleUpload(uploadId,1);
}
else{
if(overwriteConfirmChecked) overwrite='skip';
uploadsArray[uploadId]['state']='canceled';
progressSetText('PB'+uploadId,"<?php echo cfCaption('transfersCanceled');?>");
uploadProcessNext();
}
}
// Update progress (called by flash)
function uploadSetProgress(bytes,bytesTotal){
progressSetPerc('PB'+uploadId,Math.floor(100*bytes/bytesTotal));
if(bytes==bytesTotal) progressSetText('PB'+uploadId,sizeFormat(bytes)+'/'+sizeFormat(bytesTotal)+' (<img src="/gfx/loading.gif" style="height:1em;width:1em;vertical-align:middle">)');
else progressSetText('PB'+uploadId,sizeFormat(bytes)+'/'+sizeFormat(bytesTotal)+' ('+(Math.floor(100*bytes/bytesTotal))+' %)');
uploadsArray[uploadId]['bytes']=bytes;
updateTotals();
}
// Upload error (called by flash, or by async response of transfer id request)
function uploadError(errTxt){
progressSetPerc('PB'+uploadId,0);
progressSetError(uploadId);
if(errTxt=='403') progressSetText('PB'+uploadId,"<?php echo cfCaption('explorerErrorFileSend2');?>");
else progressSetText('PB'+uploadId,"<?php echo cfCaption('transfersFailed')?> ("+errTxt+")");
uploadsArray[uploadId]['state']='error';
if(errTxt=='IO err' && location.protocol=='https:') alert(httpsErrorCaption);
else uploadProcessNext();
}
// Upload completed (called by flash)
function uploadCompleted(){
if(uploadsArray[uploadId]['state']=='error') return;
progressSetPerc('PB'+uploadId,100);
progressSetText('PB'+uploadId,"<?php echo cfCaption('transfersFinished')?> ("+sizeFormat(uploadsArray[uploadId]['size'])+")");
uploadsArray[uploadId]['state']='completed';
uploadsArray[uploadId]['bytes']=uploadsArray[uploadId]['size'];
updateTotals();
uploadProcessNext();
}
// Upload canceled (called by flash)
function uploadCanceled(){
progressSetError(uploadId);
progressSetText('PB'+uploadId,"<?php echo cfCaption('transfersCanceled')?>");
uploadErrorAnim(uploadId);
uploadsArray[uploadId]['state']='canceled';
uploadProcessNext();
}
function uploadErrorAnim(id){
var p=(progressGetPerc('PB'+id)*0.9); if(p<1)p=0;
progressSetPerc('PB'+id,p);
if(p) window.setTimeout('uploadErrorAnim("'+id+'")',10);
}
// Process next upload
function uploadProcessNext(){
if(dgi('CANCELBT'+uploadId)) wl.button.disable('CANCELBT'+uploadId);
for(id in uploadsArray) if(uploadsArray[id]['state']=='pending'){
startSingleUpload(id);
return;
}
// All uploads completed
uploadsCompleted=1;
uploadsInProgress=0;
winMe.closeable(true);
//dgi('flashPlayerSpan').innerHTML+=" ";
// Close window if requested and if no error
if(dgi('transferCloseOnCompleted').checked) {
closeMe=1;
for(id in uploadsArray) if(uploadsArray[id]['state']=='error') closeMe=0;
if(closeMe) winMe.closeMe();
}
if(showAddFilesBt) wl.button.enable('addFilesBt');
else{
wl.getFlashPlayer('flashUpload').width=<?php echo FLASH_PLAYER_WIDTH;?>;
wl.getFlashPlayer('flashUpload').height=<?php echo FLASH_PLAYER_HEIGHT;?>;
}
}
</script>
</head>
<body onresize="initLayout()">
<?php // Form used to ask for a transfer id ?>
<form id="newUploadTransfer" style="display:none">
<input name="createUploadTransfer" value="1">
<input name="preUlDir" type="text" value="<?php echo cfUTF8Encode(cfResourceRelativePath(cfRGetVar('efCurrentDirectory')));?>">
<input name="preUlFile" type="text" >
<input name="overwrite" type="text" value="0">
<input name="overwriteConfirmChecked" type="text">
</form>
<div id="uploadTemplate" style="display:none">
<?php echo str_replace('<','<','<td id="TRID?" class="eTCLeft" style="text-align:left;width:15em;overflow:hidden;text-overflow:ellipsis;-o-text-overflow:ellipsis;white-space:nowrap;">NAME?</td><td>'.outProgressBar(0,'100%','LABEL','PBID?').'</td><td class="eTCRight" style="text-align:center;width:5em">'.outButton(false,'javascript:removeSingleFile(\'ID?\')',outIcon('cancel'),cfCaption('transferRemove'),'CANCELBTID?','').'</td>');?>
</div>
<?php
echo outDivFrame('frame1','id="frame1"');
echo outFrameHeaderTable('frame1Header',
// Loading icon
outImage(outIcon('loading'),false,'id="loadingIcon"','vertical-align:middle').
// HTML add files button
outButton(cfCaption('addFiles'),'javascript:addFiles()',outIcon('addMult'),false,'addFilesBt','style="display:none"').
// Flash player
'<span id="flashPlayerSpan">'.outFlashPlayer('/js/upload.swf','flashUpload',250,FLASH_PLAYER_HEIGHT).'</span>',
// Send button
outButtonDisabled(cfCaption('genSend'),'javascript:startUploads()',outIcon('upload'),false,'startUploads')
);
/**
* OVERFLOW FRAME
*/
echo outDivFrame('frame2','id="uploadsDiv"'.outEHoverFrameAttr(),'overflow:auto');
?>
<table style="width:100%;layout:fixed" id="uploadsTable" cellpadding="0" cellspacing="0" border="0">
<?php
echo '</table>'; //table
echo '</div>'; // uploadsDiv
echo outFrameHeaderTable('','<div class="warning" style="white-space:nowrap;overflow:hidden">'.cfCaption('transferCfgDest').cfCaption('genSeparator').efDirLabel(cfRGetVar('efCurrentDirectory')).'</div>'.cfCaption('explorerTotalSize').cfCaption('genSeparator').'<span id="totals"></span>',insertCloseOnCompletedControlFlash(),'id="destination"');
echo '</div>'; // frame1
?>
<script type="text/javascript">
document.onkeypress=keyPressed;
init();
</script>
</body>